]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensionUtils: Use signals rather than callbacks for finding extensions
authorJasper St. Pierre <jstpierre@mecheye.net>
Mon, 4 Jun 2012 21:14:18 +0000 (17:14 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Tue, 12 Jun 2012 21:16:08 +0000 (17:16 -0400)
This allows us to move to a file-monitor based approach in the future.

Since we need signals, we convert the current set of functions to an
object we attach signals too, leading to the new ExtensionFinder object.

https://bugzilla.gnome.org/show_bug.cgi?id=677586

js/extensionPrefs/main.js
js/misc/extensionUtils.js
js/ui/extensionSystem.js

index a403cdb7fa39107ed6142052dd51882ee9bdfba0..90fd9abc67f88186daa365c0bbfe3362217b8503 100644 (file)
@@ -202,24 +202,29 @@ const Application = new Lang.Class({
     },
 
     _scanExtensions: function() {
-        ExtensionUtils.scanExtensions(Lang.bind(this, function(uuid, dir, type) {
-            if (ExtensionUtils.extensions[uuid] !== undefined)
-                return;
-
-            let extension;
-            try {
-                extension = ExtensionUtils.createExtensionObject(uuid, dir, type);
-            } catch(e) {
-                logError(e, 'Could not create extensions object');
-                return;
-            }
-
-            let iter = this._model.append();
-            this._model.set(iter, [0, 1], [uuid, extension.metadata.name]);
-            this._extensionIters[uuid] = iter;
-        }));
+        let finder = new ExtensionUtils.ExtensionFinder();
+        finder.connect('extension-found', Lang.bind(this, this._extensionFound));
+        finder.scanExtensions();
     },
 
+    _extensionFound: function(signals, uuid, dir, type) {
+        if (ExtensionUtils.extensions[uuid] !== undefined)
+            return;
+
+        let extension;
+        try {
+            extension = ExtensionUtils.createExtensionObject(uuid, dir, type);
+        } catch(e) {
+            logError(e, 'Could not create extensions object');
+            return;
+        }
+
+        let iter = this._model.append();
+        this._model.set(iter, [0, 1], [uuid, extension.metadata.name]);
+        this._extensionIters[uuid] = iter;
+    },
+
+
     _onActivate: function() {
         this._window.present();
     },
index d08648413cbcc0b0708265e82779159dec8eca72..3eaa1b9e4dd5b97c70c307c586b9ed6da93f3d2b 100644 (file)
@@ -3,6 +3,9 @@
 // Common utils for the extension system and the extension
 // preferences tool
 
+const Lang = imports.lang;
+const Signals = imports.signals;
+
 const GLib = imports.gi.GLib;
 const Gio = imports.gi.Gio;
 const ShellJS = imports.gi.ShellJS;
@@ -149,36 +152,41 @@ function installImporter(extension) {
     _extension = null;
 }
 
-function scanExtensionsInDirectory(callback, dir, type) {
-    let fileEnum;
-    let file, info;
-    try {
-        fileEnum = dir.enumerate_children('standard::*', Gio.FileQueryInfoFlags.NONE, null);
-    } catch(e) {
-        logError(e, 'Could not enumerate extensions directory');
-        return;
-    }
-
-    while ((info = fileEnum.next_file(null)) != null) {
-        let fileType = info.get_file_type();
-        if (fileType != Gio.FileType.DIRECTORY)
-            continue;
-        let uuid = info.get_name();
-        let extensionDir = dir.get_child(uuid);
-        callback(uuid, extensionDir, type);
-    }
-    fileEnum.close(null);
-}
-
-function scanExtensions(callback) {
-    let userExtensionsDir = Gio.File.new_for_path(GLib.build_filenamev([global.userdatadir, 'extensions']));
-    scanExtensionsInDirectory(callback, userExtensionsDir, ExtensionType.PER_USER);
+const ExtensionFinder = new Lang.Class({
+    Name: 'ExtensionFinder',
+
+    _scanExtensionsInDirectory: function(dir, type) {
+        let fileEnum;
+        let file, info;
+        try {
+            fileEnum = dir.enumerate_children('standard::*', Gio.FileQueryInfoFlags.NONE, null);
+        } catch(e) {
+            logError(e, 'Could not enumerate extensions directory');
+            return;
+        }
 
-    let systemDataDirs = GLib.get_system_data_dirs();
-    for (let i = 0; i < systemDataDirs.length; i++) {
-        let dirPath = GLib.build_filenamev([systemDataDirs[i], 'gnome-shell', 'extensions']);
-        let dir = Gio.file_new_for_path(dirPath);
-        if (dir.query_exists(null))
-            scanExtensionsInDirectory(callback, dir, ExtensionType.SYSTEM);
+        while ((info = fileEnum.next_file(null)) != null) {
+            let fileType = info.get_file_type();
+            if (fileType != Gio.FileType.DIRECTORY)
+                continue;
+            let uuid = info.get_name();
+            let extensionDir = dir.get_child(uuid);
+            this.emit('extension-found', uuid, extensionDir, type);
+        }
+        fileEnum.close(null);
+    },
+
+    scanExtensions: function() {
+        let userExtensionsDir = Gio.File.new_for_path(GLib.build_filenamev([global.userdatadir, 'extensions']));
+        this._scanExtensionsInDirectory(userExtensionsDir, ExtensionType.PER_USER);
+
+        let systemDataDirs = GLib.get_system_data_dirs();
+        for (let i = 0; i < systemDataDirs.length; i++) {
+            let dirPath = GLib.build_filenamev([systemDataDirs[i], 'gnome-shell', 'extensions']);
+            let dir = Gio.file_new_for_path(dirPath);
+            if (dir.query_exists(null))
+                this._scanExtensionsInDirectory(dir, ExtensionType.SYSTEM);
+        }
     }
-}
+});
+Signals.addSignalMethods(ExtensionFinder.prototype);
index efb9144ea4cfad15544228a5de42ebda4b0f1098..902ecb691ff4d3b5ad95553f30678050f0597c29 100644 (file)
@@ -262,8 +262,10 @@ function init() {
 }
 
 function loadExtensions() {
-    ExtensionUtils.scanExtensions(function(uuid, dir, type) {
+    let finder = new ExtensionUtils.ExtensionFinder();
+    finder.connect('extension-found', function(signals, uuid, dir, type) {
         let enabled = enabledExtensions.indexOf(uuid) != -1;
         loadExtension(dir, type, enabled);
     });
+    finder.scanExtensions();
 }